package personal.lijun.skeleton.springcloud.common.data;

/**
 * @Auther: lijun@sstcsoft.com
 * @Date: 2019/9/10 14:22
 */
public class ApiResultSet<T> {
    /**
     * 执行成功代码
     */
    public final static int SUCCESS = 200;

    /**
     * 未知错误代码
     */
    public final static int UNKNOWN_ERROR = 500;

    /**
     * 参数验证错误代码
     */
    public final static int PARAM_VALID_ERROR= 501;

    /**
     * 脏数据错误
     */
    public final static int DIRTY_DATA_ERROR= 502;

    public ApiResultSet(){
        this(SUCCESS);
    }

    public ApiResultSet(int code){
        this(code,null,null);
    }

    public ApiResultSet(int code,String message,String stackTrace){
        this.setCode(code);
        this.setMessage(message);
        this.setStackTrace(stackTrace);
    }

    //执行代码
    private int code;
    //详细错误日志
    private String message;
    //日志异常栈信息
    private String stackTrace;
    //执行成功后的数据
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getStackTrace() {
        return stackTrace;
    }

    public void setStackTrace(String stackTrace) {
        this.stackTrace = stackTrace;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String toFullMessage(){
        StringBuilder sb = new StringBuilder();
        sb.append("调用远程服务出错，错误代码："+ code);
        sb.append("\r\n");
        sb.append(message);
        sb.append("\r\n");
        sb.append(stackTrace);
        return sb.toString();
    }
}
